/*
 License
 
 Copyright © 2012 Kevin Kimmich
 
 Permission is hereby granted, free of charge, to any person obtaining a copy
 of this software and associated documentation files (the "Software"), to deal
 in the Software without restriction, including without limitation the rights to 
 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
 the Software, and to permit persons to whom the Software is furnished to do so, 
 subject to the following conditions:
 
 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
 INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
 PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
 FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

/**
 @file
 Utility functions for libxml
 */

#ifndef __xmlutils_h
#define __xmlutils_h

#ifdef __cplusplus
extern "C" {
#endif


#include "config.h"

#ifdef ENABLE_LIBXML

/**
 Dump an XML node (libxml2) to stdout.
 */
void print_node(xmlNodePtr node);

/*!
 Get the contents of a libxml2 node.
 @param node pointer to the node
 */
char* get_node_content(xmlNodePtr node);

/**
 copy a node, no children or siblings.
 */
xmlNodePtr copy_node(xmlNodePtr node);

/**
 copy a node and it's children.
 */
xmlNodePtr recursive_copy_node(xmlNodePtr node);

/**
 Get an attribute value.
 @param node The node.
 @param attr_name The name of the attribute to retrieve.
 */
xmlChar *get_attribute_value(xmlNodePtr node, const char*attr_name);

/**
 Get a copy of the attribute value. Caller must free.
 @param node the node.
 @param attr_name The name of the attribute.
 */
xmlChar *get_attribute_value_copy(xmlNodePtr node, const char* attr_name);

/**
 Get the node of the attribute.
 @param node The node.
 @param attr_name The name of the attribute to get.
 */
xmlNodePtr get_attribute_node(xmlNodePtr node, const char* attr_name) ;

/**
 Do an xpath query, returning the node list.
 */
xmlXPathObjectPtr quick_query( xmlXPathContextPtr ctx, xmlNodePtr ctx_node, const char* query_format, ... );

/**
 Do an xpath query that should return one node.
 */
xmlNodePtr quick_query_node( xmlXPathContextPtr ctx, xmlNodePtr ctx_node, const char* query_format, ... );

/**
 Add a property (attribute) to a node.
 */
void quick_prop( xmlNodePtr node, const char* name, const char* format, ... );

/**
 Get the content (inner text) of a node.
 */
char* get_node_content(xmlNodePtr node);

/**
 Remove extra white space from a document.
 */
void remove_extra_line_feeds(xmlDocPtr doc);

/**
 Recursively make subdirectories, like mkdir -p
 */
int mkdir_p(char* path);

/**
 Get an attribute cast to integer.
 */
int get_attribute_value_as_int(xmlNodePtr node, const char* name);

#endif

#ifdef __cplusplus
}
#endif

	
#endif
